package com.hxzy.shop.controller;

import com.github.pagehelper.PageInfo;
import com.hxzy.shop.constant.AuthConstant;
import com.hxzy.shop.dto.auth.req.MerchantListReq;
import com.hxzy.shop.dto.auth.req.MerchantRemarkReq;
import com.hxzy.shop.dto.auth.resp.MerchantInfoResp;
import com.hxzy.shop.dto.auth.resp.MerchantListResp;
import com.hxzy.shop.dto.auth.resp.MerchantResp;
import com.hxzy.shop.entity.MerchantRemark;
import com.hxzy.shop.service.MerchantService;
import com.hxzy.shop.utils.WebUtil;
import com.hxzy.shop.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wy
 * @Description 商户API
 * @Date 2023/5/6 17:11
 * @Version 1.0
 */
@RestController
@Api(tags = "商户管理")
@RequestMapping("/merchant")
public class MerchantController {

    @Autowired
    private MerchantService merchantService;


    @ApiOperation("商户列表")
    @PostMapping("/getMerchantList")
    public Result<PageInfo<MerchantListResp>> getMerchantList(@RequestBody MerchantListReq req) {
        return Result.success(merchantService.getMerchantList(req));
    }

    @ApiOperation("商户的企业信息")
    @PostMapping("/merchantInfo")
    public Result<MerchantInfoResp> getMerchantInfo(@ApiParam(required = true, name = "id", value = "商户id")
                                                    @RequestParam("id") Long id) {
        return Result.success(merchantService.getMerchantInfo(id));
    }

    /**
     * 商户备注列表
     */
    @ApiOperation("商户备注列表")
    @PostMapping("/getMerchantRemarkList")
    public Result<PageInfo<MerchantRemark>> getMerchantRemarkList(@RequestBody MerchantRemarkReq req) {
        return Result.success(merchantService.getMerchantRemarkList(req));
    }

    @ApiOperation("获取商户详情")
    @PostMapping("/detail")
    public Result<MerchantResp> getMerchantDetail() {
        String merchantId = WebUtil.getRequest().getHeader("merchantId");
        return Result.success(merchantService.getMerchantDetail(Long.parseLong(merchantId)));
    }

    @ApiOperation(value = "商户门店数量限制")
    @GetMapping(value = "/storeCount")
    public Result<Integer> selectStoreCount( ){
        String merchantId = WebUtil.getRequest().getHeader("merchantId");

        return Result.success(this.merchantService.selectStoreCount(Long.parseLong(merchantId)));
    }
}
